'''
Created on 08.03.2012

@author: cwestphal
'''

import maya.cmds as cmds


class fatBakeWindow ():

     
    def bakeTex(self):
        
        #self.path = cmds.textFieldButtonGrp("textGrp1",edit=True,text=True)
        self.name = cmds.textFieldButtonGrp("textGrp2",query=True,text=True)
        bakeAnimTex(self.name)
        cmds.deleteUI('window', window = True)

    def __init__(self):
        
        if cmds.window('window', exists = True):
            cmds.deleteUI('window', window = True)
            
        window = cmds.window('window', title = 'Bake Animated Texture', widthHeight = [200,20], sizeable = False)
        cmds.columnLayout()
        self.name = ''
        singleFilter = "All Files (*.*)"
        #cmds.textFieldButtonGrp("textGrp1", label='Sequence Path:', text = self.name, buttonLabel ='Browse', buttonCommand = 'cmds.fileDialog2(fileFilter = \'All Files (*.*)\', fileMode = 3, dialogStyle=2)')
        cmds.textFieldButtonGrp("textGrp2", label='Sequence Path:', text = self.name, buttonLabel ='Save', buttonCommand=self.bakeTex)
        cmds.showWindow(window)

def bakeAnimTex(texName):

    startTime = cmds.playbackOptions(query = True, animationStartTime = True)
    endTime = cmds.playbackOptions(query = True, animationEndTime = True)

    for i in range (startTime, endTime):
    
        cmds.currentTime(i)
        cmds.convertSolidTx(antiAlias = True, fileFormat = 'bmp', fileImageName = '%s%s.bmp' %(texName, i), name = 'tmp', force = True)
        cmds.delete('tmp')
